using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_PDC
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                default:
                    dwReturn["ABAID"] = "      ";
                    dwReturn["TERMNO"] = "        ";
                    dwReturn["PROCESSED"] = " ";
                    dwReturn["NEWDATE"] = "0";
                    dwReturn["NEWTIME"] = "0";
                    dwReturn["NEWUSER"] = "        ";
                    dwReturn["CHGDATE"] = 0;
                    dwReturn["CHGTIME"] = 0;
                    dwReturn["CHGUSER"] = "        ";
                    dwReturn["ABFSTEP"] = "                    ";
                    dwReturn["ABFMANDANT"] = "00";
                    dwReturn["ABKAUFART"] = "  ";
                    dwReturn["ABPWAKZ"] = " ";
                    dwReturn["ABPART"] = "                    ";
                    dwReturn["ABPVAR"] = "   ";
                    dwReturn["ABPFARBE"] = "          ";
                    dwReturn["ABPDESS"] = "          ";
                    dwReturn["ABPCOLORIT"] = "          ";
                    dwReturn["ABPBESCHICH"] = "          ";
                    dwReturn["ABFAUFKRS"] = "  ";
                    dwReturn["ABFAUFLFD"] = "      ";
                    dwReturn["ABFAUFPOS"] = "   ";
                    dwReturn["ABFAFOLGE"] = "   ";
                    dwReturn["ABFFIX"] = " ";
                    dwReturn["ABFME"] = " ";
                    dwReturn["ABFKSTKRS"] = "  ";
                    dwReturn["ABFKST"] = "    ";
                    dwReturn["ABFEVARUNR"] = "  ";
                    dwReturn["ABFEVARHNR"] = "  ";
                    dwReturn["ABFMANUELKZ"] = "N";
                    dwReturn["ABFAGANG"] = "        ";
                    dwReturn["ABFBZAGANG"] = "                                                            ";
                    dwReturn["MKFTP"] = "0000";
                    dwReturn["QTY"] = 0;
                    dwReturn["ABFSTART"] = " ";
                    dwReturn["ABFEND"] = " ";
                    dwReturn["MACHINEID"] = "        ";
                    dwReturn["ABFIMNRKRS"] = "  ";
                    dwReturn["ABFIMLFDNR"] = "    ";
                    dwReturn["ABFIMPOS"] = "  ";
                    dwReturn["AMSTKBIS"] = "0";
                    dwReturn["AMBDEMA"] = "        ";
                    dwReturn["AMAUFTRVON"] = "0";
                    dwReturn["AMAUFTRBIS"] = "0";
                    dwReturn["AMBEZ"] = "                                        ";
                    dwReturn["PDCFLAG"] = "N";
                    dwReturn["PDCDATE"] = "0";
                    dwReturn["PDCTIMES"] = "0";
                    dwReturn["PDCTIMET"] = "0";
                    dwReturn["PDCTIME"] = "0";
                    dwReturn["PDCSTAFF"] = "0";
                    dwReturn["PDCSHIFT"] = "3";
                    dwReturn["JP01"] = "0";
                    dwReturn["JP02"] = "0";
                    dwReturn["JP03"] = "0";
                    dwReturn["JP04"] = "0";
                    dwReturn["JP05"] = "0";
                    dwReturn["JP06"] = "0";
                    dwReturn["JP07"] = "0";
                    dwReturn["JP08"] = "0";
                    dwReturn["JP09"] = "0";
                    dwReturn["JP10"] = "0";
                    dwReturn["JP11"] = "0";
                    dwReturn["JP12"] = "0";
                    dwReturn["JP13"] = "0";
                    dwReturn["JP14"] = "0";
                    dwReturn["JP15"] = "0";
                    dwReturn["JP16"] = "0";
                    dwReturn["JP17"] = "0";
                    dwReturn["JP18"] = "0";
                    dwReturn["JP19"] = "0";
                    dwReturn["JP20"] = "0";
                    dwReturn["JP21"] = "0";
                    dwReturn["JP22"] = "0";
                    dwReturn["JP23"] = "0";
                    dwReturn["JP24"] = "0";
                    dwReturn["JP25"] = "0";
                    dwReturn["JP26"] = "0";
                    dwReturn["JP27"] = "0";
                    dwReturn["JP28"] = "0";
                    dwReturn["JP29"] = "0";
                    dwReturn["JP30"] = "0";
                    break;
            }
        }
        public DataRow Convert2ICC_PDC(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_PDC(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {

                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_PDC(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_PDC(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            switch (ITXDBVERSION)
            {
                case "JLT":
                case "YGR":
                default:
                    Result = QueryICC_PDC(dwData);
                    if (Result.Tables.Count > 0)
                    {
                        tbLocal = Result.Tables[0];
                        if (tbLocal.Rows.Count > 0)
                        {
                            flgExist = true;
                            dwLocal = tbLocal.Rows[0];
                        }
                        else
                        {
                            dwLocal = tbLocal.NewRow();
                        }
                    }

                    MapICC_PDC(ref dwLocal, dwData);

                    if (!flgExist)
                    {
                        //dwLocal["ABAID"] = GetSeq();
                        InsertICC_PDC(dwLocal, 1);
                    }
                    UpdateICC_PDC(dwLocal, 1);
                    break;
            }
        }
        public void DeleteICC_PDC(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_PDC WHERE ABAID=:ABAID";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_PDC WHERE ABFMANDANT=:ABFMANDANT  AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD AND ABFAUFPOS=:ABFAUFPOS AND ABFAFOLGE=:ABFAFOLGE ";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    or1.Parameters.Add("ABFAFOLGE", OracleType.NVarChar).Value = dwData["ABFAFOLGE"].ToString();
                    break;
                case 3:
                    or1.CommandText = "DELETE FROM ICC_PDC WHERE RTRIM(ABFSTEP)=:ABFSTEP";
                    or1.Parameters.Add("ABFSTEP", OracleType.NVarChar).Value = dwData["ABFSTEP"].ToString().Trim();
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_PDC(DataRow dwData, int option = 1)
        { 
            or1 = OracleDB.CreateCommand();
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            string FSARTPRGR = "";
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_PDC WHERE ROWNUM<2";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_PDC WHERE ABAID=:ABAID";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_PDC WHERE ABFMANDANT=:ABFMANDANT AND ABAAUFKRS=:ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABAAUFPOS=:ABAAUFPOS AND ABFAFOLGE=:ABFAFOLGE";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    or1.Parameters.Add("ABFAFOLGE", OracleType.NVarChar).Value = dwData["ABFAFOLGE"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT MAX(ABAID) AS MAXORD FROM ICC_PDC WHERE RTRIM(TERMNO)=:TERMNO";
                    or1.Parameters.Add("TERMNO", OracleType.NVarChar).Value = dwData["TERMNO"].ToString().Trim();
                    break;
                case 4:
                    or1.CommandText = "SELECT* FROM ICC_PDC WHERE PDCSTAFF=:PDCSTAFF AND ABFAGANG=:ABFAGANG AND NEWDATE LIKE '" + dwData["NEWDATE"].ToString().Trim() + "%'";
                    or1.Parameters.Add("PDCSTAFF", OracleType.NVarChar).Value = dwData["PDCSTAFF"].ToString();
                    or1.Parameters.Add("ABFAGANG", OracleType.NVarChar).Value = dwData["ABFAGANG"].ToString();
                    break;
                case 5:
                    or1.CommandText = "select A.ABFAGANG,TRIM(A.ABFBZAGANG) AS ZAGANG,to_number(substr(pdcdate,5,2))||'-'||to_number(substr(pdcdate,7,2)) AS DAT,A.PDCDATE,A.JP10,A.ABFAUFKRS,A.ABFAUFLFD,A.ABFAUFPOS,B.ABPART,B.ABPFARBE, "
                        + " A.AMBDEMA,A.PDCSTAFF,A.PDCSHIFT,A.QTY,A.AMAUFTRVON,A.JP03,A.JP02,A.JP06,A.JP12"
                        + " from icc_pdc A,ABPOS B  "
                        + " where A.ABFMANDANT = B.ABPMANDANT AND A.ABFAUFKRS = B.ABPAUFKRS "
                        + " AND A.ABFAUFLFD = B.ABPAUFLFD AND A.ABFAUFPOS = B.ABPAUFPOS "
                        + " AND TRIM(ABFAGANG) = '" + dwData["TYPE"].ToString() + "'  "
                        + " AND PDCDATE >= '" + dwData["FROMDATE"].ToString() + "' AND PDCDATE <=  '" + dwData["ENDDATE"].ToString() + "' "
                        + " AND (TRIM(JP10) =  '" + dwData["LOT"].ToString() + "' or  '" + dwData["LOT"].ToString() + "' = 'AAA') "
                        + " AND TRIM(PDCSTAFF) LIKE '" + dwData["STAFF"].ToString() + "%' "
                        + " AND (TRIM(AMBDEMA) =  '" + dwData["BDE"].ToString() + "' OR  '" + dwData["BDE"].ToString() + "' = 'AAA') "
                        + " ORDER BY PDCDATE,AMBDEMA,JP10 ";
                    //or1.Parameters.Add("TYPE", OracleType.NVarChar).Value = dwData["TYPE"].ToString();
                    //or1.Parameters.Add("FROMDATE", OracleType.NVarChar).Value = dwData["FROMDATE"].ToString();
                    //or1.Parameters.Add("ENDDATE", OracleType.NVarChar).Value = dwData["ENDDATE"].ToString();
                    //or1.Parameters.Add("BDE", OracleType.NVarChar).Value = dwData["BDE"].ToString();
                    //or1.Parameters.Add("LOT", OracleType.NVarChar).Value = dwData["LOT"].ToString();
                    break;
                case 6:
                    or1.CommandText = "SELECT YARN,SUM(QTY) AS QTY,COUNT "
                        + " FROM ( SELECT A.PDCDATE, "
                        + " (SELECT NVL(MAX(TRIM(SUBSTR(VKPKDBEZ,21,10))||SUBSTR(VKPART,INSTR(VKPART,'.',1,2)+1,INSTR(VKPART,'.',1,3)-INSTR(VKPART,'.',1,2)-1)||'S'),'N/A') "
                        + " FROM ICC_ABAX X,VKPOS Y  "
                        + " WHERE X.ABAAUFKRS = A.ABFAUFKRS AND X.ABAAUFLFD = A.ABFAUFLFD "
                        + " AND X.ABAVKAUFTYP = 'K' AND Y.VKPSA <> 'AJ' "
                        + " AND X.ABAMANDANT = Y.VKPMANDANT AND X.ABAVKAUFKRS = Y.VKPAUFKRS "
                        + " AND X.ABAVKAUFLFD = Y.VKPAUFLFD AND X.ABAVKAUFPOS = Y.VKPAUFPOS) as yarn, "
                        + " QTY,B.GSRECHNR*0.0001 AS COUNT "
                        + " FROM ICC_PDC A,ABPOS C,GSDAT B "
                        + " WHERE A.ABFMANDANT = C.ABPMANDANT AND A.ABFAUFKRS = C.ABPAUFKRS "
                        + " AND A.ABFAUFLFD = C.ABPAUFLFD AND A.ABFAUFPOS = C.ABPAUFPOS "
                        + " AND C.ABPMANDANT = B.GSMANDANT AND C.ABPART = B.GSART "
                        + " AND C.ABPVAR = B.GSVAR "
                        + " and qty>0 and PDCDATE >=:FROMDATE AND PDCDATE <=:ENDDATE AND TRIM(A.ABFAGANG) = :TYPE ) "
                        + " GROUP BY YARN,COUNT "
                        + " UNION ALL "
                        + " SELECT 'ZZTOTAL',SUM(QTY) AS QTY,ROUND(SUM(QTY)/SUM(AVGCOUNT),5) AS COUNT "
                        + " FROM ( SELECT A.PDCDATE, "
                        + " QTY,B.GSRECHNR*0.0001 AS COUNT,ROUND(QTY/(B.GSRECHNR*0.0001),5) AS AVGCOUNT "
                        + " FROM ICC_PDC A,ABPOS C,GSDAT B "
                        + " WHERE A.ABFMANDANT = C.ABPMANDANT AND A.ABFAUFKRS = C.ABPAUFKRS "
                        + " AND A.ABFAUFLFD = C.ABPAUFLFD AND A.ABFAUFPOS = C.ABPAUFPOS "
                        + " AND C.ABPMANDANT = B.GSMANDANT AND C.ABPART = B.GSART "
                        + " AND C.ABPVAR = B.GSVAR "
                        + " AND QTY>0 and PDCDATE >=:FROMDATE AND PDCDATE <=:ENDDATE AND TRIM(A.ABFAGANG) = :TYPE ) "
                        + " order by 1 ";
                    or1.Parameters.Add("FROMDATE", OracleType.NVarChar).Value = dwData["FROMDATE"].ToString();
                    or1.Parameters.Add("ENDDATE", OracleType.NVarChar).Value = dwData["ENDDATE"].ToString();
                    or1.Parameters.Add("TYPE", OracleType.NVarChar).Value = dwData["TYPE"].ToString();
                    break;
            }
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PDC"; 
            
            return SResult;
        }
        public DataSet QPDC06(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT YARN,SUM(QTY) AS QTY,COUNT "
                       + " FROM ( SELECT A.PDCDATE, "
                       + " (SELECT NVL(MAX(TRIM(SUBSTR(VKPKDBEZ,21,10))||SUBSTR(VKPART,INSTR(VKPART,'.',1,2)+1,INSTR(VKPART,'.',1,3)-INSTR(VKPART,'.',1,2)-1)||'S'),'N/A') "
                       + " FROM ICC_ABAX X,VKPOS Y  "
                       + " WHERE X.ABAAUFKRS = A.ABFAUFKRS AND X.ABAAUFLFD = A.ABFAUFLFD "
                       + " AND X.ABAVKAUFTYP = 'K' AND Y.VKPSA <> 'AJ' "
                       + " AND X.ABAMANDANT = Y.VKPMANDANT AND X.ABAVKAUFKRS = Y.VKPAUFKRS "
                       + " AND X.ABAVKAUFLFD = Y.VKPAUFLFD AND X.ABAVKAUFPOS = Y.VKPAUFPOS) as yarn, "
                       + " QTY,B.GSRECHNR*0.0001 AS COUNT "
                       + " FROM ICC_PDC A,ABPOS C,GSDAT B "
                       + " WHERE A.ABFMANDANT = C.ABPMANDANT AND A.ABFAUFKRS = C.ABPAUFKRS "
                       + " AND A.ABFAUFLFD = C.ABPAUFLFD AND A.ABFAUFPOS = C.ABPAUFPOS "
                       + " AND C.ABPMANDANT = B.GSMANDANT AND C.ABPART = B.GSART "
                       + " AND C.ABPVAR = B.GSVAR "
                       + " and qty>0  "+dwData["PDCDATE"].ToString()+ " AND TRIM(A.ABFAGANG) = :ABFAGANG: ) "
                       + " GROUP BY YARN,COUNT "
                       + " UNION ALL "
                       + " SELECT 'ZZTOTAL',SUM(QTY) AS QTY,ROUND(SUM(QTY)/SUM(AVGCOUNT),5) AS COUNT "
                       + " FROM ( SELECT A.PDCDATE, "
                       + " QTY,B.GSRECHNR*0.0001 AS COUNT,ROUND(QTY/(B.GSRECHNR*0.0001),5) AS AVGCOUNT "
                       + " FROM ICC_PDC A,ABPOS C,GSDAT B "
                       + " WHERE A.ABFMANDANT = C.ABPMANDANT AND A.ABFAUFKRS = C.ABPAUFKRS "
                       + " AND A.ABFAUFLFD = C.ABPAUFLFD AND A.ABFAUFPOS = C.ABPAUFPOS "
                       + " AND C.ABPMANDANT = B.GSMANDANT AND C.ABPART = B.GSART "
                       + " AND C.ABPVAR = B.GSVAR "
                       + " AND QTY>0 " + dwData["PDCDATE"].ToString() + "  AND TRIM(A.ABFAGANG) = :ABFAGANG: ) "
                       + " order by 1 ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QPDC05(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "select A.ABFAGANG,TRIM(A.ABFBZAGANG) AS ZAGANG,to_number(substr(pdcdate,5,2))||'-'||to_number(substr(pdcdate,7,2)) AS DAT,A.PDCDATE,A.JP10,A.ABFAUFKRS,A.ABFAUFLFD,A.ABFAUFPOS,B.ABPART,B.ABPFARBE, "
                         + " A.AMBDEMA,A.PDCSTAFF,A.PDCSHIFT,A.QTY,A.AMAUFTRVON,A.JP03,A.JP02,A.JP06,A.JP12,A.JP20,A.JP24,A.JP25,A.JP26,A.JP27,A.JP28,a.JP14,a.JP15,a.JP16 "
                         + " from icc_pdc A,ABPOS B  "
                         + " where A.ABFMANDANT = B.ABPMANDANT AND A.ABFAUFKRS = B.ABPAUFKRS "
                         + " AND A.ABFAUFLFD = B.ABPAUFLFD AND A.ABFAUFPOS = B.ABPAUFPOS "
                         + " AND TRIM(ABFAGANG) = :ABFAGANG: "
                         + dwData["PDCDATE"].ToString()
                         + dwData["JP10"].ToString()
                          + dwData["PDCSTAFF"].ToString()
                           + dwData["AMBDEMA"].ToString()
                         + " ORDER BY PDCDATE,PDCSHIFT,ABFIMLFDNR ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        
        public void UpdateICC_PDC(DataRow dwData, int option, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                    case "JLT":
                        option = 1;
                        break;
                }
            }
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE ICC_PDC SET ABAID=:ABAID:,TERMNO=:TERMNO:,PROCESSED=:PROCESSED:,NEWDATE=:NEWDATE:,NEWTIME=:NEWTIME:,NEWUSER=:NEWUSER:,CHGDATE=:CHGDATE:,CHGTIME=:CHGTIME:,CHGUSER=:CHGUSER:,ABFSTEP=:ABFSTEP:,ABFMANDANT=:ABFMANDANT:,ABKAUFART=:ABKAUFART:,ABPWAKZ=:ABPWAKZ:,ABPART=:ABPART:,ABPVAR=:ABPVAR:,ABPFARBE=:ABPFARBE:,ABPDESS=:ABPDESS:,ABPCOLORIT=:ABPCOLORIT:,ABPBESCHICH=:ABPBESCHICH:,ABFAUFKRS=:ABFAUFKRS:,ABFAUFLFD=:ABFAUFLFD:,ABFAUFPOS=:ABFAUFPOS:,ABFAFOLGE=:ABFAFOLGE:,ABFFIX=:ABFFIX:,ABFME=:ABFME:,ABFKSTKRS=:ABFKSTKRS:,ABFKST=:ABFKST:,ABFEVARUNR=:ABFEVARUNR:,ABFEVARHNR=:ABFEVARHNR:,ABFMANUELKZ=:ABFMANUELKZ:,ABFAGANG=:ABFAGANG:,ABFBZAGANG=:ABFBZAGANG:,MKFTP=:MKFTP:,QTY=:QTY:,ABFSTART=:ABFSTART:,ABFEND=:ABFEND:,MACHINEID=:MACHINEID:,ABFIMNRKRS=:ABFIMNRKRS:,ABFIMLFDNR=:ABFIMLFDNR:,ABFIMPOS=:ABFIMPOS:,AMSTKBIS=:AMSTKBIS:,AMBDEMA=:AMBDEMA:,AMAUFTRVON=:AMAUFTRVON:,AMAUFTRBIS=:AMAUFTRBIS:,AMBEZ=:AMBEZ:,PDCFLAG=:PDCFLAG:,PDCDATE=:PDCDATE:,PDCTIMES=:PDCTIMES:,PDCTIMET=:PDCTIMET:,PDCTIME=:PDCTIME:,PDCSTAFF=:PDCSTAFF:,PDCSHIFT=:PDCSHIFT:,JP01=:JP01:,JP02=:JP02:,JP03=:JP03:,JP04=:JP04:,JP05=:JP05:,JP06=:JP06:,JP07=:JP07:,JP08=:JP08:,JP09=:JP09:,JP10=:JP10:,JP11=:JP11:,JP12=:JP12:,JP13=:JP13:,JP14=:JP14:,JP15=:JP15:,JP16=:JP16:,JP17=:JP17:,JP18=:JP18:,JP19=:JP19:,JP20=:JP20:,JP21=:JP21:,JP22=:JP22:,JP23=:JP23:,JP24=:JP24:,JP25=:JP25:,JP26=:JP26:,JP27=:JP27:,JP28=:JP28:,JP29=:JP29:,JP30=:JP30:"
                     + " WHERE ABAID=:ABAID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 2:
                    or1.CommandText = "UPDATE ICC_PDC SET JP30=( CASE WHEN JP01>80 THEN 'XSBM80' WHEN  JP01<=80 AND JP01>=40 THEN  'XSBL80'  WHEN  JP01<40 AND JP01>=30 THEN  'XSBL40' WHEN  JP01<30 THEN  'XSBL30'   END)  WHERE  ABPFARBE ='000000    '  AND JP30='0' AND ABFAGANG='XS      '";
                    break;
                case 3:
                    or1.CommandText = "UPDATE ICC_PDC SET JP30=( CASE WHEN JP01>70 THEN 'XSHM70' WHEN  JP01<=70 AND JP01>=49 THEN  'XSHL70'  WHEN  JP01<49 AND JP01>=36 THEN  'XSHL49'  WHEN  JP01<36 AND JP01>=26 THEN  'XSHL36' WHEN  JP01<26 AND JP01>=16 THEN  'XSHL26' WHEN  JP01<16 THEN  'XSHL16'   END)  WHERE  ABPFARBE <>'000000    ' AND JP30='0' AND ABFAGANG='XS      '";
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void InsertICC_PDC(DataRow dwData, int option, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_PDC (ABAID,ABPWAKZ,ABPART,ABPVAR,ABPFARBE,ABPDESS,ABPCOLORIT,ABPBESCHICH) VALUES (:ABAID,:ABPWAKZ,:ABPART,:ABPVAR,:ABPFARBE,:ABPDESS,:ABPCOLORIT,:ABPBESCHICH)";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    or1.Parameters.Add("ABPWAKZ", OracleType.NVarChar).Value = dwData["ABPWAKZ"].ToString();
                    or1.Parameters.Add("ABPART", OracleType.NVarChar).Value = dwData["ABPART"].ToString();
                    or1.Parameters.Add("ABPVAR", OracleType.NVarChar).Value = dwData["ABPVAR"].ToString();
                    or1.Parameters.Add("ABPFARBE", OracleType.NVarChar).Value = dwData["ABPFARBE"].ToString();
                    or1.Parameters.Add("ABPDESS", OracleType.NVarChar).Value = dwData["ABPDESS"].ToString();
                    or1.Parameters.Add("ABPCOLORIT", OracleType.NVarChar).Value = dwData["ABPCOLORIT"].ToString();
                    or1.Parameters.Add("ABPBESCHICH", OracleType.NVarChar).Value = dwData["ABPBESCHICH"].ToString();
                    break;
                case "JLT":
                    or1.CommandText = " INSERT INTO ICC_PDC ( ABAID,TERMNO,PROCESSED,NEWDATE,NEWTIME,NEWUSER,CHGDATE,CHGTIME,CHGUSER,ABFSTEP,ABFMANDANT,ABKAUFART,ABPWAKZ,ABPART,ABPVAR,ABPFARBE,ABPDESS,ABPCOLORIT,ABPBESCHICH,ABFAUFKRS,ABFAUFLFD,ABFAUFPOS,ABFAFOLGE,ABFFIX,ABFME,ABFKSTKRS,ABFKST,ABFEVARUNR,ABFEVARHNR,ABFMANUELKZ,ABFAGANG,ABFBZAGANG,MKFTP,QTY,ABFSTART,ABFEND,MACHINEID,ABFIMNRKRS,ABFIMLFDNR,ABFIMPOS,AMSTKBIS,AMBDEMA,AMAUFTRVON,AMAUFTRBIS,AMBEZ,PDCFLAG,PDCDATE,PDCTIMES,PDCTIMET,PDCTIME,PDCSTAFF,PDCSHIFT,JP01,JP02,JP03,JP04,JP05,JP06,JP07,JP08,JP09,JP10,JP11,JP12,JP13,JP14,JP15,JP16,JP17,JP18,JP19,JP20,JP21,JP22,JP23,JP24,JP25,JP26,JP27,JP28,JP29,JP30)"
                    + " VALUES (:ABAID:,:TERMNO:,:PROCESSED:,:NEWDATE:,:NEWTIME:,:NEWUSER:,:CHGDATE:,:CHGTIME:,:CHGUSER:,:ABFSTEP:,:ABFMANDANT:,:ABKAUFART:,:ABPWAKZ:,:ABPART:,:ABPVAR:,:ABPFARBE:,:ABPDESS:,:ABPCOLORIT:,:ABPBESCHICH:,:ABFAUFKRS:,:ABFAUFLFD:,:ABFAUFPOS:,:ABFAFOLGE:,:ABFFIX:,:ABFME:,:ABFKSTKRS:,:ABFKST:,:ABFEVARUNR:,:ABFEVARHNR:,:ABFMANUELKZ:,:ABFAGANG:,:ABFBZAGANG:,:MKFTP:,:QTY:,:ABFSTART:,:ABFEND:,:MACHINEID:,:ABFIMNRKRS:,:ABFIMLFDNR:,:ABFIMPOS:,:AMSTKBIS:,:AMBDEMA:,:AMAUFTRVON:,:AMAUFTRBIS:,:AMBEZ:,:PDCFLAG:,:PDCDATE:,:PDCTIMES:,:PDCTIMET:,:PDCTIME:,:PDCSTAFF:,:PDCSHIFT:,:JP01:,:JP02:,:JP03:,:JP04:,:JP05:,:JP06:,:JP07:,:JP08:,:JP09:,:JP10:,:JP11:,:JP12:,:JP13:,:JP14:,:JP15:,:JP16:,:JP17:,:JP18:,:JP19:,:JP20:,:JP21:,:JP22:,:JP23:,:JP24:,:JP25:,:JP26:,:JP27:,:JP28:,:JP29:,:JP30:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
